package com.dymedia.aibo.mvp.ui;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.KeyEvent;

import com.dymedia.aibo.R;
import com.dymedia.aibo.app.utils.Utils;
import com.dymedia.aibo.mvp.model.Entity.Channel;
import com.dymedia.aibo.mvp.model.Entity.Group;
import com.dymedia.aibo.mvp.ui.widget.TvMenuView;

import java.util.ArrayList;
import java.util.List;

import timber.log.Timber;

public class TestActivity extends Activity {
    TvMenuView mTvMenuView;
    List<Group> groups = new ArrayList<>();
    Handler handler = new Handler();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_test);
        mTvMenuView = (TvMenuView)findViewById(R.id.tvmenuview);

        initTestData();
        mTvMenuView.setDatas(groups);
        mTvMenuView.notifyDataSetChanged();
//        mTvMenuView.setOnObserverCallback(channel -> {
//            Timber.e("setOnObserverCallback, "+channel.url);
//        });
//        handler.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                Utils.findFocusView(TestActivity.this);
//                handler.postDelayed(this, 3000);
//            }
//        }, 4000);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode){
            case KeyEvent.KEYCODE_DPAD_UP:
                if (!mTvMenuView.isShow()){
                    mTvMenuView.show();
                    return true;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                if (!mTvMenuView.isShow()){
                    mTvMenuView.show();
                    return true;
                }
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    private void initTestData(){
        Group g = new Group();
        g._id = "1";
        g.name = "group1";
        g.channels = new ArrayList<>();
        Channel c = new Channel();
        c._id = "1";
        c.name = "channel1";
        c.url = "url1";
        g.channels.add(c);
        c = new Channel();
        c._id = "11";
        c.name = "channel1";
        c.url = "url2";
        g.channels.add(c);
        groups.add(g);

        g = new Group();
        g._id = "2";
        g.name = "group2";
        g.channels = new ArrayList<>();
        c = new Channel();
        c._id = "2";
        c.name = "channel2";
        c.url = "url2";
        g.channels.add(c);
        c._id = "22";
        c.name = "channel22";
        c.url = "url22";
        g.channels.add(c);
        g.channels.add(c);
        c._id = "23";
        c.name = "channel23";
        c.url = "url23";
        g.channels.add(c);
        groups.add(g);
    }
}
